<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
		<script src="https://code.jquery.com/jquery-3.1.1.min.js"></script>
		<style>
		     .mytime{ line-height: 40px; width: 300px; margin: 0 auto;}
		 </style>
	</head>
	<body>
		<div class="mytime jsTime" data-time="2019-12-10 16:58:00">时间1</div>
<!-- 		<div class="mytime jsTime" data-time="2019-12-11 18:00:02">时间2</div>
		<div class="mytime jsTime" data-time="2019-12-12 19:01:31">时间3</div>
		<div class="mytime jsTime" data-time="2019-12-13 05:05:15">时间4</div>
		<div class="mytime jsTime" data-time="2019-12-14 09:01:43">时间5</div> -->
		<hr>
		<div class="mytime jsTime2" data-time="2019-12-15 16:30:05">时间1</div>
		<div class="mytime jsTime2" data-time="2019-12-16 14:01:22">时间2</div>
		<div class="mytime jsTime2" data-time="2019-12-17 18:06:25">时间3</div>
		<div class="mytime jsTime2" data-time="2019-12-18 22:07:19">时间4</div>
		<div class="mytime jsTime2" data-time="2019-12-19 23:12:38">时间5</div>
	
	
	<script>
	    const countdown = {
	        domList : document.querySelectorAll('.jsTime'),
	        formatNumber(n){
	            // return n.toString().padStart(2, '0');  // 用padStart方法要注意兼容问题
	            n = n.toString();
	            return n[1] ? n : '0' + n;
	        },
	        setTime(dom){
	            //获取设置的时间 如：2019-3-28 14:00:00  ios系统得加正则.replace(/\-/g, '/');
	            const leftTime = new Date(dom.getAttribute('data-time').replace(/\-/g, '/')) - new Date();
				console.log(leftTime);
				console.log("--------------------------------------");
				if (leftTime >= 0) {
	                const d = Math.floor(leftTime / 1000 / 60 / 60 / 24);
	                const h = Math.floor(leftTime / 1000 / 60 / 60 % 24);
	                const m = Math.floor(leftTime / 1000 / 60 % 60);
	                const s = Math.floor(leftTime / 1000 % 60);
	                dom.innerHTML = `剩余${ d > 0 ? d + '天' : '' }${ [h, m, s].map(this.formatNumber).join(':') }`;
	            } else {
	                clearInterval(dom.$timer);
	                dom.innerHTML = '拼团已结束';
	            }
	        },
	        start(){
	            this.domList.forEach((dom) => {
	                this.setTime(dom);
	                dom.$timer = setInterval(() => {
	                    this.setTime(dom);
	                }, 1e3);
	            });
	        },
	    };
	    countdown.start();
	</script>

	</body>
	
	
</html>
